package com.htdata.iiot.kafka2tsdb.dataParser;

import com.alibaba.fastjson.JSONObject;
import com.htdata.iiot.kafka2tsdb.dataParser.pojo.DataPoint;
import com.htdata.iiot.kafka2tsdb.dataParser.pojo.StreamingData;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.List;

public class DataParser {
	private static Logger logger = Logger.getLogger(DataParser.class);

	private static DataParser dataParser = new DataParser();

	public static DataParser getDataParser() {
		return dataParser;
	}

	public StreamingData toStreamingData(String data) {
		return JSONObject.parseObject(data, StreamingData.class);
	}

	public static List<DataPoint> convent(List<StreamingData> streamDataList){
		List<DataPoint> metrics = new ArrayList<>();
		for(StreamingData streamData:streamDataList) {
			DataPoint convent = convent(streamData);
			metrics.add(convent);
		}
		return metrics;
	}

	public static DataPoint convent(StreamingData streamData){
		DataPoint dp = new DataPoint();
		dp.setMetric(streamData.getDid());
		dp.setTimestamp(streamData.getTs());
		dp.addTags("tid",streamData.getTid());
		dp.setValue(streamData.getSts());
		return dp;
	}
}
